﻿using System;
using Microsoft.Xna.Framework;
using ThinkDotNetBotApiCommon;

namespace CircleBot
{
    public class CircleBot : BotBase
    {
        private double _currentOffset;
        private long _currentSleepTime;
        private const long MaxSleepTime = 10000;
        private const double Radius = 100;
        private const double OffsetSpeed = MathHelper.PiOver4;

        public CircleBot(IBotController botController)
            : base(botController)
        {
        }

        private BotMetadata _botMetadata;
        public override BotMetadata Metadata
        {
            get
            {
                if (_botMetadata == null)
                {
                    _botMetadata = new BotMetadata { Name = "Circle" };
                }
                return _botMetadata;
            }
        }
        public override void Update(GameTime gameTime)
        {
            if (_currentSleepTime < MaxSleepTime)
            {
                _currentSleepTime += gameTime.ElapsedGameTime.Milliseconds;
                return;
            }
            else
                _currentSleepTime = 0;
                  
            
            if (BotController.IsMoving == false)
            {
                _currentOffset += OffsetSpeed;

                double nextXPos = Radius * Math.Sin(_currentOffset);
                double nextZPos = Radius * Math.Cos(_currentOffset);
                Vector3 destination = BotController.Translation + new Vector3((float) nextXPos, 0, (float) nextZPos);

                BotController.Move(destination);
            }
        }
    }
}
